<!DOCTYPE html> 
<html> 
<head>  
    <!--META-->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=0.75">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">

    <!--CSS-->
    <link rel="stylesheet" href="API/css/themes/default/jquery.mobile.min.css" />
    <link rel="stylesheet" href="API/css/themes/default/jquery.mobile.structure.min.css" />
    <link rel="stylesheet" href="API/css/themes/default/jquery.mobile.theme.min.css" />
    <link rel="stylesheet" href="API/css/mycss.css" />
    <link rel="stylesheet" href="css/mycss.css" />

    <!--JS-->
    <script type="text/javascript" src="API/js/jquery.min.js"></script>
    <script type="text/javascript" src="API/js/jquery.mobile.min.js"></script>
    <!--<script type="text/javascript" src="API/js/highcharts.js"></script>-->
    <!--<script type="text/javascript" src="API/js/modules/exporting.js"></script>-->
    <!--<script type="text/javascript" src="API/js/jquery.dataTables.min.js"></script>--> 
    <script type="text/javascript" src="include/config.js"></script>
    <script type="text/javascript" src="API/js/fonctions.js"></script>
    <script type="text/javascript" src="js/fonctions.js"></script>

    <script language="javascript" type="text/javascript">
    checkMaintenance();
    checkAuthentification();
	
    ///////////////////
    //BLOCK VARIABLE GLOBAL
    ///////////////////
    var id_page = 31;

    ///////////////////
    //BLOCK FONCTIONS EVENEMENTS
    ///////////////////
    //A la construction de la page
    $(document).on('pageinit',function() {
        try {
            // Init commmun
            init_commun();

            // Init page
        }
        catch (er) {
            log(0, "ERROR(init_home):" + er.message);
        }
    });

    //Affichage de la page avant onload
    $(document).on('pageshow',function() {
        try {
            show_commun();
        }
        catch (er) {
            log(0, "ERROR(show):" + er.message);
        }
    });

    //Fin chargement page
    function OnLoad() {
        try {
            //
            afficheTickets();
        }
        catch (er) {
            log(0, "ERROR(refreshG):" + er.message);
        }
    }

    ///////////////////
    //BLOCK FONCTIONS METIER
    ///////////////////
    /**
     * Affiche la liste des tickets en supp/deb et leur statut
     * 
     */
    function afficheTickets(){
        try {
            strhtml = "<img src=\"API/img/loading.gif\" alt=\"loading\" style=\"vertical-align:middle;\" />";
            $('#div_tabTickets').html(strhtml).trigger('create');
            var tabInput = { code_user : "" };
            callBD(domaine+"phpsql/mysql_getTicketsSupDeb.php", "GET", "text", tabInput, "vue_tickets", true);
        }
        catch (er) {
            log(0, "ERROR(afficheTickets):" + er.message);
        }
    }
    
    /**
     * Met à jour la valeur du périmètre pour le ticket
     * 
     * @param {obj JS} p_obj
     */
    function radioChange(p_obj){
        try {
            var nom = p_obj.name;
            var reg = new RegExp("[_]+", "g");
            var tableau = nom.split(reg);
            var id_toc = tableau[1];
            var revision = tableau[2];
            var valeur = p_obj.value;
            
            var tabInput = { id_toc:id_toc, revision:revision, sn3:valeur,  code_user:auth  };
            callBD(domaine+"phpsql/mysql_setStatutTicketsSupDeb.php", "GET", "text", tabInput, null, true);   
        }
        catch (er) {
            log(0, "ERROR(radioChange):" + er.message);
        }
    }

    ///////////////////
    //BLOCK FONCTIONS BD
    ///////////////////

    ///////////////////
    //BLOCK FONCTIONS AFFICHAGE
    ///////////////////
    function vue_tickets(p_retour){
        try {
            var stats = {revision0:{total:0,sn3:0,horsSn3:0}, retour:{total:0,sn3:0,horsSn3:0}, total:0};
            
            //[x][0]id_toc_ori 
            //[x][1]id_toc 
            //[x][2]revision 
            //[x][3]responsable 
            //[x][4]date_creation 
            //[x][5]date_statut 
            //[x][6]libelle
            //[x][7]sn3 
            //[x][8]code_user 
            //[x][9]date_creation
            //[x][10]date_modif
            var strhtml = "";
            strhtml += "<table id=\"tabLaListe\" data-role=\"table\" data-mode=\"reflow\" class=\"ui-body-d table-stripe ui-responsive\">";
            strhtml += "<thead>";
            strhtml += "<TR class=\"ui-bar-d\">";
            strhtml += "<TH>N&deg;</TH>";
            strhtml += "<TH>Id</TH>";
            strhtml += "<TH>R&eacute;vision</TH>";
            strhtml += "<TH>Responsable</TH>";
            strhtml += "<TH>Libell&eacute;</TH>";
            strhtml += "<TH>P&eacute;rim&egrave;tre SN3</TH>";
            strhtml += "<TH>Depuis</TH>";
            strhtml += "</thead>";
            strhtml += "<tbody>";
            for (var indice in p_retour) {
                stats.total ++;
                if(p_retour[indice][2] == "0"){
                    stats.revision0.total ++;
                }else{
                    stats.retour.total ++;
                }
                strhtml += "<TR onMouseOver=\"changeCouleur(this);\" onMouseOut=\"remetCouleur(this);\" >";
                strhtml += "<TD>"+stats.total+"</TD>";
                strhtml += "<TD><a target=\"_new\" href=\"http://10.197.68.30:4000/AutoDiseWeb/automate/popupModule.jsp?modType=SIG_SIG&modCode=" + p_retour[indice][0] + "\">" + p_retour[indice][1] + "</a> </TD>";
                strhtml += "<TD>"+p_retour[indice][2]+"</TD>";
                strhtml += "<TD>"+p_retour[indice][3]+"</TD>";
                strhtml += "<TD>"+p_retour[indice][6].substring(0,50);+"</TD>";
                strhtml += "<TD>";
                strhtml += "<fieldset data-role=\"controlgroup\" data-type=\"horizontal\" data-mini=\"true\">";
                var strChecked = "";
                if(p_retour[indice][7] == "1"){
                    strChecked = "checked=\"checked\"";
                    if(p_retour[indice][2] == "0"){
                        stats.revision0.sn3 ++;
                    }else{
                        stats.retour.sn3 ++;
                    }
                }
                strhtml += "<input type=\"radio\" name=\"InputRadio_"+p_retour[indice][1]+"_"+p_retour[indice][2]+"\" id=\"InputRadio_"+p_retour[indice][1]+"_"+p_retour[indice][2]+"_1\" value=\"1\" "+strChecked+" onchange=\"radioChange(this);\" />";
                strhtml += "<label for=\"InputRadio_"+p_retour[indice][1]+"_"+p_retour[indice][2]+"_1\">Oui</label>";
                var strChecked = "";
                if(p_retour[indice][7] == "0"){
                    strChecked = "checked=\"checked\"";
                    if(p_retour[indice][2] == "0"){
                        stats.revision0.horsSn3 ++;
                    }else{
                        stats.retour.horsSn3 ++;
                    }
                }
                strhtml += "<input type=\"radio\" name=\"InputRadio_"+p_retour[indice][1]+"_"+p_retour[indice][2]+"\" id=\"InputRadio_"+p_retour[indice][1]+"_"+p_retour[indice][2]+"_0\" value=\"0\" "+strChecked+"  onchange=\"radioChange(this);\"/>";
                strhtml += "<label for=\"InputRadio_"+p_retour[indice][1]+"_"+p_retour[indice][2]+"_0\">Non</label>";
                strhtml += "</fieldset>";
                
                var depuis = "";
                if(p_retour[indice][10] == "0000-00-00 00:00:00"){
                    depuis = p_retour[indice][9];
                }else{
                    depuis = p_retour[indice][10];
                }
                
                if(depuis != ""){
                    depuis = getStrDateFrFromUs(depuis.substr(0,10)) + depuis.substr(10,9);
                }
                
                strhtml += "<TD>"+depuis+"</TD>";
                strhtml += "</TD>";
                strhtml += "</TR>";
            }
            strhtml += "</tbody>";
            strhtml += "</table>";
            
            var strHtml2 = "";
            strHtml2 += "<table data-role=\"table\" data-mode=\"reflow\" class=\"ui-body-d table-stripe ui-responsive\">";
            strHtml2 += "<thead>";
            strHtml2 += "<TR class=\"ui-bar-d\">";
            strHtml2 += "<TH>Périmètre</TH>";
            strHtml2 += "<TH>Nombre</TH>";
            strHtml2 += "</thead>";
            strHtml2 += "<tbody>";
            strHtml2 += "<TR onMouseOver=\"changeCouleur(this);\" onMouseOut=\"remetCouleur(this);\" >";
            strHtml2 += "<TD>Ticket(s) dans le périmètre SN3</TD>";
            strHtml2 += "<TD>"+stats.revision0.sn3+"</TD>";
            strHtml2 += "</TR>";
            strHtml2 += "<TR onMouseOver=\"changeCouleur(this);\" onMouseOut=\"remetCouleur(this);\" >";
            strHtml2 += "<TD>Ticket(s) dans hors du périmètre SN3</TD>";
            strHtml2 += "<TD>"+stats.revision0.horsSn3+"</TD>";
            strHtml2 += "</TR>";
            strHtml2 += "<TR onMouseOver=\"changeCouleur(this);\" onMouseOut=\"remetCouleur(this);\" >";
            strHtml2 += "<TD>Ticket(s) dans pas renseigné</TD>";
            strHtml2 += "<TD>"+(stats.revision0.total - (stats.revision0.horsSn3 + stats.revision0.sn3))+"</TD>";
            strHtml2 += "</TR>";
            strHtml2 += "<TR onMouseOver=\"changeCouleur(this);\" onMouseOut=\"remetCouleur(this);\" >";
            strHtml2 += "<TD>Total des tickets</TD>";
            strHtml2 += "<TD>"+stats.revision0.total+"</TD>";
            strHtml2 += "</TR>";
            strHtml2 += "<TR onMouseOver=\"changeCouleur(this);\" onMouseOut=\"remetCouleur(this);\" >";
            strHtml2 += "<TD>Retour(s) dans le périmètre SN3</TD>";
            strHtml2 += "<TD>"+stats.retour.sn3+"</TD>";
            strHtml2 += "</TR>";
            strHtml2 += "<TR onMouseOver=\"changeCouleur(this);\" onMouseOut=\"remetCouleur(this);\" >";
            strHtml2 += "<TD>Retour(s) hors périmètre SN3</TD>";
            strHtml2 += "<TD>"+stats.retour.horsSn3+"</TD>";
            strHtml2 += "</TR>";
            strHtml2 += "<TR onMouseOver=\"changeCouleur(this);\" onMouseOut=\"remetCouleur(this);\" >";
            strHtml2 += "<TD>Retour(s) pas renseigné</TD>";
            strHtml2 += "<TD>"+(stats.retour.total - (stats.retour.horsSn3 + stats.retour.sn3))+"</TD>";
            strHtml2 += "</TR>";
            strHtml2 += "<TR onMouseOver=\"changeCouleur(this);\" onMouseOut=\"remetCouleur(this);\" >";
            strHtml2 += "<TD>Total des retours</TD>";
            strHtml2 += "<TD>"+stats.retour.total+"</TD>";
            strHtml2 += "</TR>";
            strHtml2 += "<TR onMouseOver=\"changeCouleur(this);\" onMouseOut=\"remetCouleur(this);\" >";
            strHtml2 += "<TD>Total</TD>";
            strHtml2 += "<TD>"+stats.total+"</TD>";
            strHtml2 += "</TR>";
            strHtml2 += "</tbody>";
            strHtml2 += "</table>";
            
            
            var strHtmlFinal = "";
            strHtmlFinal += "<center>";
            strHtmlFinal += strHtml2;
            strHtmlFinal += "<br>";
            strHtmlFinal += strhtml;
            strHtmlFinal += "</center>";
            
            $('#div_tabTickets').html(strHtmlFinal).trigger('create');
        }
        catch (er) {
            log(0, "ERROR(vue_tickets):" + er.message);
        }
    }
</script>

</head>
<body onload="OnLoad();">

    <!-- page -->
    <div data-role="page" data-title="Titre">

        <!-- /panel -->
        <div data-role="panel" id="mypanel" data-display="overlay" data-position="left">

        </div>
        <!-- /panel -->

        <!-- header -->
        <div data-role="header" data-position="fixed">
            <a href="#mypanel" data-role="button" data-icon="home" data-iconpos="notext">home</a>
            <h1 id="id_titre">titre</h1>
            <a href="javascript:window.location = ('./page_contact.html?mili='+getMilise());" data-role="button" data-icon="info" data-iconpos="notext">Contact</a>
        </div>
        <!-- /header -->

        <!-- content -->
        <div data-role="content" id="main_content">
            <div data-role="collapsible" data-collapsed="false" data-mini="true">
                <h3>Les tickets</h3>
                <div id="div_tabTickets">Anomalie code EXXX</div>
            </div>
        </div>
        <!-- /content -->

        <!-- footer -->
        <div data-role="footer" data-position="fixed">
            <a data-role="button" data-icon="search" data-iconpos="notext" class="ui-btn-left" href="javascript:window.location = ('./page_faq.html?mili='+getMilise());">FAQ</a>
            <h1 id="id_affichageUser">User</h1>
            <a data-role="button" data-icon="delete" data-iconpos="notext" class="ui-btn-right" href="javascript:window.location = ('./page_sortie.html?mili='+getMilise());">Logout</a>
        </div>
        <!-- /footer -->

    </div>
    <!-- /page -->
</body>
</html>